<script setup>
import Cookie from 'js-cookie'
import {ElMessage} from "element-plus";
import axios from "axios";
import qs from "qs";

const goHome = () => {
  window.location.href='/index'
}

const logout = () => {
  Cookie.remove("token")
  axios.post('/api/logout',qs.stringify({
    username:Cookie.get("username")
  })).then(res=>{
    ElMessage.success(res.data.msg)
    Cookie.remove("username")
    location.href='/login'
  })
}
</script>

<template>
  <div class="app-container">
    <!-- 导航栏 -->
    <header class="navbar">
      <div class="nav-container">
        <div class="nav-brand">
          <div class="brand-icon">🎮</div>
          <h1 class="brand-title">3D资源分享站</h1>
        </div>
        
        <div class="nav-actions">
          <el-button 
            @click="goHome" 
            class="nav-btn home-btn"
            size="large"
          >
            <span class="btn-icon">🏠</span>
            首页
          </el-button>
          <el-button 
            type="danger" 
            @click="logout" 
            class="nav-btn logout-btn"
            size="large"
          >
            <span class="btn-icon">🚪</span>
            注销
          </el-button>
        </div>
      </div>
    </header>

    <!-- 主内容区域 -->
    <main class="main-content">
      <div class="content-wrapper">
        <router-view/>
      </div>
    </main>
  </div>
</template>

<style scoped>
.app-container {
  min-height: 100vh;
  background: var(--gradient-dark);
  display: flex;
  flex-direction: column;
}

.navbar {
  background: rgba(26, 26, 46, 0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(79, 70, 229, 0.3);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
}

.nav-container {
  width: 100%;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
  box-sizing: border-box;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 32px;
  animation: pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}

.brand-title {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-gold), var(--white));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
  white-space: nowrap;
}

.nav-actions {
  display: flex;
  gap: 15px;
  align-items: center;
  flex-shrink: 0;
  justify-content: flex-end;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 600;
  transition: all 0.3s ease;
  height: 45px;
  white-space: nowrap;
  flex-shrink: 0;
}

.home-btn {
  background: linear-gradient(135deg, var(--accent-gray), var(--light-gray)) !important;
  border: 1px solid var(--accent-gray) !important;
  color: var(--white) !important;
}

.home-btn:hover {
  background: linear-gradient(135deg, var(--light-gray), var(--accent-gray)) !important;
  border-color: var(--accent-gold) !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.2);
}

.logout-btn {
  background: linear-gradient(135deg, #dc3545, #c82333) !important;
  border: 1px solid #dc3545 !important;
  color: var(--white) !important;
}

.logout-btn:hover {
  background: linear-gradient(135deg, #c82333, #dc3545) !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(220, 53, 69, 0.3);
}

.btn-icon {
  font-size: 16px;
}

.main-content {
  flex: 1;
  padding: 30px 20px;
  width: 100%;
  min-height: calc(100vh - 70px);
}

.content-wrapper {
  background: rgba(26, 26, 26, 0.8);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: fadeInUp 0.6s ease-out;
  width: 100%;
  min-height: calc(100vh - 130px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .nav-container {
    padding: 0 15px;
    height: 60px;
  }
  
  .brand-title {
    font-size: 20px;
  }
  
  .brand-icon {
    font-size: 28px;
  }
  
  .nav-actions {
    gap: 10px;
  }
  
  .nav-btn {
    padding: 10px 15px;
    height: 40px;
    font-size: 14px;
  }
  
  .main-content {
    padding: 20px 15px;
  }
  
  .content-wrapper {
    padding: 20px;
  }
}

@media (max-width: 480px) {
  .nav-container {
    padding: 0 10px;
    height: 55px;
  }
  
  .brand-title {
    font-size: 18px;
  }
  
  .brand-icon {
    font-size: 24px;
  }
  
  .nav-brand {
    gap: 10px;
  }
  
  .nav-actions {
    gap: 8px;
  }
  
  .nav-btn {
    padding: 8px 12px;
    height: 35px;
    font-size: 12px;
  }
  
  .btn-icon {
    font-size: 14px;
  }
}


</style>